﻿using Sofia.Models;
using Sofia.Web.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

namespace Sofia.Web.Controllers
{
    [Authorize]
    public class CreateForumController : Controller
    {
        SofiaDb db = new SofiaDb();
        //
        // GET: /CreateForum/
        public ActionResult Love()
        {
            return View();
        }
        public ActionResult Index(love loves)
        {
            var currentUser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new love
            {
                Title = Server.HtmlDecode(loves.Title),
                Description = Server.HtmlDecode(loves.Description),
                CreationTime = DateTime.Now,
                UserName = currentUser,
            };
            db.Loves.Add(post);
            db.SaveChanges();
            return Redirect("/");
        }

        public ActionResult Corps()
        {
            return View();
        }

        public ActionResult Corp(Corp corps)
        {
            var currentUser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new Corp
            {
                Title = Server.HtmlDecode(corps.Title),
                Description = Server.HtmlDecode(corps.Description),
                CreationTime = DateTime.Now,
                userName = currentUser,
            };
            db.Corps.Add(post);
            db.SaveChanges();
            return Redirect("/");
        }

        public ActionResult SysAdmins()
        {
            return View();
        }

        public ActionResult SysAdmin(SysAdmin admins)
        {
            var currentUser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new SysAdmin
            {
                Title = Server.HtmlDecode(admins.Title),
                CreationTime = DateTime.Now,
                Description = Server.HtmlDecode(admins.Description),
                UserName = currentUser,
            };
            return Redirect("/");
        }

        public ActionResult Storys()
        {
            return View();
        }

        public ActionResult Story(Story story)
        {
            var currentuser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new Story
            {
                Title = Server.HtmlDecode(story.Title),
                Description = Server.HtmlDecode(story.Description),
                CreationTime = DateTime.Now,
                UserName = currentuser,
            };
            db.Storys.Add(post);
            db.SaveChanges();
            return Redirect("/");
        }
        
        public ActionResult Manages()
        {
            return View();
        }

        public ActionResult Manage(manage manage)
        {
            var currentUser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new manage
            {
                Title = Server.HtmlDecode(manage.Title),
                Description = Server.HtmlDecode(manage.Description),
                CreationTime = DateTime.Now,
                userName = currentUser,
            };
            db.Manages.Add(post);
            db.SaveChanges();
            return Redirect("/");
        }
        
        public ActionResult Markets()
        {
            return View();
        }

        public ActionResult Market(Market market)
        {
            var currentUser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new Market
            {
                Title = Server.HtmlDecode(market.Title),
                Description = Server.HtmlDecode(market.Description),
                CreationTime = DateTime.Now,
                userName = currentUser,
            };
            db.Markets.Add(post);
            db.SaveChanges();
            return Redirect("/");
        }

        public ActionResult Programs()
        {
            return View();
        }

        public ActionResult Program(Program programs)
        {
            var currentUser = db.UserProfiles.FirstOrDefault(x => x.UserName == WebSecurity.CurrentUserName);
            var post = new Program
            {
                Title = Server.HtmlDecode(programs.Title),
                Description = Server.HtmlDecode(programs.Description),
                CreationTime = DateTime.Now,
                UserName = currentUser,
            };
            db.Programs.Add(post);
            db.SaveChanges();
            return Redirect("/");
        }
    }
}
